package local.blueheart.data.springdatademo.domino;

import local.blueheart.data.springdatademo.exception.DominoException;
import local.blueheart.data.springdatademo.exception.DominoExceptionEnum;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.NotesException;
import lotus.domino.View;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DDatabase extends DBase {

    private static final Logger LOGGER = LoggerFactory.getLogger(DDatabase.class);

    public DDatabase(Database database){
        super(database);
    }

    public DView getView(String viewName) throws DominoException {
        try {
            Database database = (Database) getBase();
            View view = database.getView(viewName);
            DView dView = new DView(view);
            addChild(dView);
            return dView;
        }catch (NotesException ne){
            LOGGER.error("获取View出错",ne);
            throw new DominoException(ne, DominoExceptionEnum.GET_VIEW_ERR);
        }
    }

    public DDocument getDocument(String docId) throws DominoException {
        try {
            Database database = (Database) getBase();
            Document document = database.getDocumentByUNID(docId);
            DDocument dDocument =  new DDocument(document);
            addChild(dDocument);
            return dDocument;
        }catch (NotesException ne){
            LOGGER.error("从数据库获取文档出错",ne);
            throw new DominoException(ne,DominoExceptionEnum.GET_DOC_ERR);
        }
    }



}
